<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目报价方案</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
			<div tabid="tabA" title="基本信息" lselected="true">
	            <form id="formSet1">
	                <div class="fieldset1 tabel_col clearFix">
	                    <div class="fieldBox col_33">
		                    <div class="label">方案名称</div>
		                    <div class="field">
		                   <input name="prpsCfgNm" id="prpsCfgNm" type="text" class="ui-textbox"   readonly="readonly" value="${quatPrps.prpsCfgNm}" >
		                   <input name="prpsCfgId" id="prpsCfgId" type="hidden" class="ui-textbox"   value="${quatPrps.id}" >
		                   <input name="isDef" id="isDef" type="hidden" class="ui-textbox"   value="${quatPrps.isSysDef}" >
		            	   <input name="prpsId" id="prpsId" type="hidden" class="ui-textbox"   value="${id}" >
		            	   <input name="isAllowChg" id="isAllowChg" type="hidden" class="ui-textbox"   value="${quatPrps.isAllowChg}" >
		            	   <input name="isAllowAdd" id="isAllowAdd" type="hidden" class="ui-textbox"   value="${quatPrps.isAllowAdd}" >
		            	   <input name="prpsTypCd" id="prpsTypCd" type="hidden" class="ui-textbox"   value="${quatPrps.prpsTypCd}" >
		            	   
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁物件总价值</div>
		                    <div class="field">
		                        <input name="totLsItmAmt" id="totLsItmAmt"  readonly="readonly" type="text" class="ui-textbox"  onblur="changeBaseTotLsltmAmt()" value="${totalPrdAmt}" validate="{required:true}">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">合同总额（元）</div>
		                    <div class="field">
		                        <input name="contAmt" id="contAmt" type="text"  readonly="readonly" class="ui-textbox"  value="${totalPrdAmt}"  onblur="changeBaseContAmt()" validate="{required:true}">
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">利率上浮比例</div>
		                    <div class="field">
		                        <input name="intRateRsPct" id="intRateRsPct"    type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div> 
		                 <div class="fieldBox col_100">
		                    <div class="label">租赁期数</div>
		                    <div class="field">
		                        <input name="lsPd" id="lsPd" type="text" class="ui-textbox"  value="${quatPrps.lsPd}"   readonly="readonly"   validate="{required:true,number:true}">
		                         <select name="lsPdUntCd" id="lsPdUntCd" data-value=" " disabled="disabled">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${lsPdUntCdList }" var="kv">
									    <option value="${kv.key }" 
									    <c:if test="${quatPrps.lsPdUntCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
								 </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁周期</div>
		                    <div class="field">
		                      <span id="rentPeriod"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁年利率%</div>
		                    <div class="field">
		                      <input name="annIntRatePct" id="annIntRatePct" type="text" class="ui-textbox"  value="" readonly="readonly">
		                    </div>
		                </div>
		               
		                  <div class="fieldBox col_33">
		                    <div class="label">支付方式</div>
		                    <div class="field">
		                        <select name="payWayCd" id="payWayCd" data-value=" "  disabled="disabled"  validate="{required:true}">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${payWayCdList }" var="kv">
									    <option value="${kv.key }"
									    <c:if test="${quatPrps.payWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">实际融资租赁价值</div>
		                    <div class="field">
		                       <input name="actLsAmt" id="actLsAmt" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">每期预估租金</div>
		                    <div class="field">
		                      <input name="eachEstRntAmt" id="eachEstRntAmt"  type="text" class="ui-textbox"  value="" readonly="readonly">
		                    </div>
		                </div>
		             
	                    <div class="fieldBox col_33">
		                    <div class="label">计算方式</div>
		                    <div class="field">
		                        <select name="lsCalWayCd" id="lsCalWayCd" data-value=" " disabled="disabled">
									<c:forEach items="${lsCalWayCdList }" var="kv">
									    <option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁系数</div>
		                    <div class="field">
		                        <input name="lsCoe" id="lsCoe" type="text" class="ui-textbox"   value="${quatPrps.lsCoe}" validate="{number:true}"  readonly="readonly">
		                    </div>
		                </div>
		               <div class="fieldBox col_33">
		                    <div class="label">租赁年利率计算方式</div>
		                    <div class="field">
		                        <select name="intRateWayCd" id="intRateWayCd" data-value=" " disabled="disabled">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${intRateWayCdList }" var="kv">
									    <option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">客户保证金处理方式</div>
		                    <div class="field">
		                        <select name="dpstHdlWayCd" id="dpstHdlWayCd" data-value=" " disabled="disabled">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${dpstHdlWayCdList }" var="kv">
									    <option value="${kv.key }"
								        <c:if test="${quatPrps.dpstHdlWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁期满处理方式</div>
		                    <div class="field">
		                        <select name="expHdlWayCd" id="expHdlWayCd" data-value=" " disabled="disabled">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${expHdlWayCdList }" var="kv">
									    <option value="${kv.key }"
				                         <c:if test="${quatPrps.expHdlWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		             <%--     <div class="fieldBox col_33">
		                    <div class="label">不还款处理方式</div>
		                    <div class="field">
		                        <select name="noPayWayCd" id="noPayWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${noPayWayCdList }" var="kv">
									    <option value="${kv.key }">${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div> --%>
		                  <div class="fieldBox col_33">
		                    <div class="label">首付款</div>
		                    <div class="field">
		                    <span id="firstPayAmt"></span>
		                    </div>
		                </div>
		               <div class="fieldBox col_33">
		                    <div class="label">实际收益率(IRR)</div>
		                    <div class="field">
		                      <input name="irrPct" id="irrPct"  type="text" class="ui-textbox"  value="" readonly="readonly" validate="{number:true}">
		                    </div>
		                </div>
						<div class="fieldBox col_33">
							<div class="label">对客IRR</div>
							<div class="field">
								<input name="cstIrr" id="cstIrr"  type="text" class="ui-textbox"  value="${cstIrr}" readonly="readonly" validate="{number:true}">
							</div>
						</div>
						<div class="fieldBox col_33"  id="isLowBizDiv">
							<div class="label">是否低息</div>
							<div class="field">
								<select name="isLowBiz" id="isLowBiz">
									<option value="0" selected="selected">否</option>
									<option value="1">是</option>
								</select>
							</div>
						</div>

						<div class="fieldBox col_33">
		                    <div class="label">实际收益率(IRR2)</div>
		                    <div class="field">
		                      <input name="irrPct2" id="irrPct2"  type="text" class="ui-textbox"  value="" readonly="readonly" validate="{number:true}">
		                    </div>
		                </div>
		                <div class="fieldBox col_33"  id="initLsPcDiv" style="display: none">
		                    <div class="label">第一年总还款比例</div>
		                    <div class="field">
		                      <input name="initLsPct" id="initLsPct"  type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		                  <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div class="sqPanel_head inL">
				                     <span>合同附加费用</span>
				                </div>
				                <div id="contFeeAmtGrid">
				                    <div id="ligergrid_cont_fee" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				        <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div id="detailGrid">
				                    <div id="ligergrid_fee" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				          <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div id="feePayGrid">
				                    <div id="ligergrid_calculate" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				         <div class="fieldBox col_33">
		                    <div class="label">合计租金：</div>
		                    <div class="field">
		                    <span id="totalRntAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计本金：</div>
		                    <div class="field">
		                    <span id="totalPrinAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计利息：</div>
		                    <div class="field">
		                    <span id="totalIntAmt"></span>
		                    </div>
		                </div>
	                </div>
	                <div class="btnsBox">
		                <input name="prpsCfgId" id="prpsCfgId" type="hidden" value="${quatPrps.id }">
		            </div>
	            </form>
		</div>
	</div>
</div>

<script type="text/javascript">
var feeGrid;//费用明细信息
var contFeeGrid;
var quatId = '${quatId}';
var prjId = '${prjId}';
var detailFlag = '${detailFlag}';
var calculateGrid;
var annIntRatePct = 0;
var isModify = false;
var prpsCfgId = '${prpsCfgId}';
var quatPrps='${quatPrps}';
var quatPrpsJson  ='${quatPrpsJson}';
var totalRsrvPcStr = '${totalRsrvPcStr}';
var prpsTypCd = '${prpsTypCd}';
//金融机构类型
var insCode = '${insCode}';
//是否低息
var isLowBiz = '${isLowBiz}';
var buOrgCd = '${buOrgCd}';
var prjTypCd = '${prjTypCd}';
//费用类型
var feeTypCdListJSON = [];
<c:if test="${not empty feeTypCdListJSON}"> feeTypCdListJSON = ${feeTypCdListJSON}; </c:if>
//费用计算基数
var calBaseCdListJSON = [];
<c:if test="${not empty calBaseCdListJSON}"> calBaseCdListJSON = ${calBaseCdListJSON}; </c:if>
//费用计入方式
var cntWayCdListJSON = [];
<c:if test="${not empty cntWayCdListJSON}"> cntWayCdListJSON = ${cntWayCdListJSON}; </c:if>
//是否
var yesOrNoCdListJSON = [];
<c:if test="${not empty yesOrNoCdListJSON}"> yesOrNoCdListJSON = ${yesOrNoCdListJSON}; </c:if>
var scaleNumMap = '${scaleNumMap}';
var feeScale = 0;
var annIntScale = 0;
var floatScale = 0;
$(function(){
	$('#formSet1').ligerForm({
        validate : true
	});
	var editFlag = true;
 	if(detailFlag=="true"){
		$("#calculateBtn1").hide();
		$("#saveBtn1").hide();
		$("#addBtn").hide();
		$("#delBtn").hide();
	}
    //默认不显示是否低息字段(新增，查看都有)
    $("#isLowBizDiv").hide();
    //重卡传统业务，重卡城配业务
    if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK
        && (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW || prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)){
        //资方为浦发，苏宁，三湘 显示是否低息
        if(insCode == ProjectConstant.PRJ_INS_CODE_PSD
            || insCode == ProjectConstant.PRJ_INS_CODE_SN
            || insCode == ProjectConstant.PRJ_INS_CODE_SNS
            || insCode == ProjectConstant.PRJ_INS_CODE_SX){
            $("#isLowBizDiv").show();
            //查看报价方案不允许修改是否低息字段
            if(isLowBiz != ""){
                if (isLowBiz ==0 || isLowBiz ==1) {
                    var selectid= $("#isLowBiz").ligerGetComboBoxManager();
                    selectid.setValue(isLowBiz);
                }
            }
            //detailFlag为true表示查看报价方案，不允许编辑
            if(detailFlag=="true"){
                liger.get("isLowBiz").setDisabled(true);
            }
        }
    }
	var prpsId=$("#prpsId").val();
	if(!prpsId){
		 var baseForm1 = liger.get("formSet1");
		 baseForm1.setData({
			 intRateWayCd:ProjectConstant.CODE_DEF_INT_RATE_WAY_CD
     	 });
	}
	if($("#prpsCfgNm")){
		$("#prpsCfgNm").attr("readonly","readonly");
	}
	if($("#totLsItmAmt")){
		$("#totLsItmAmt").attr("readonly","readonly");
	}
	if($("#contAmt")){
		$("#contAmt").attr("readonly","readonly");
	}
	if($("#lsPd")){
		$("#lsPd").attr("readonly","readonly");
	}
	if($("#annIntRatePct")){
		$("#annIntRatePct").attr("readonly","readonly");
	}
	if($("#actLsAmt")){
		$("#actLsAmt").attr("readonly","readonly");
	}
	if($("#eachEstRntAmt")){
		$("#eachEstRntAmt").attr("readonly","readonly");
	}
	if($("#lsCoe")){
		$("#lsCoe").attr("readonly","readonly");
	}
	if($("#intRateRsPct")){
		$("#intRateRsPct").attr("readonly","readonly");
	}
	
	if(liger.get("lsPdUntCd")){
		  liger.get("lsPdUntCd").setDisabled(true);
	}
	if(liger.get("payWayCd")){
		  liger.get("payWayCd").setDisabled(true);
	}
	if(liger.get("lsCalWayCd")){
		  liger.get("lsCalWayCd").setDisabled(true);
	}
	if(liger.get("intRateWayCd")){
		  liger.get("intRateWayCd").setDisabled(true);
	}
	if(liger.get("dpstHdlWayCd")){
		  liger.get("dpstHdlWayCd").setDisabled(true);
	}
	if(liger.get("expHdlWayCd")){
		  liger.get("expHdlWayCd").setDisabled(true);
	}
	if(liger.get("noPayWayCd")){
		  liger.get("noPayWayCd").setDisabled(true);
	}
	
	if(prpsId){
	var prjQuatPrps = '${prjQuatPrps}';
	 prjQuatPrps = JSON.parse(prjQuatPrps);
		//初始化修改数据
	 	 var form = liger.get("formSet1");
	 		form.setData({
	 			prpsCfgNm:prjQuatPrps.prpsCfgNm,
	 			prpsCfgId:prjQuatPrps.prpsCfgId,
	 			isSysDef:prjQuatPrps.isSysDef,
	 			prpsId:prjQuatPrps.prpsId,
	 			totLsItmAmt:prjQuatPrps.totLsItmAmt,
	 			contAmt:prjQuatPrps.contAmt,
	 			intRateRsPct:parseFloat(prjQuatPrps.intRateRsPct==null?0:prjQuatPrps.intRateRsPct),
	 			lsPd:prjQuatPrps.lsPd,
	 			lsPdUntCd:prjQuatPrps.lsPdUntCd,
	 			annIntRatePct:parseFloat(prjQuatPrps.annIntRatePct==null?0:prjQuatPrps.annIntRatePct),
	 			payWayCd:prjQuatPrps.payWayCd,
	 			actLsAmt:prjQuatPrps.actLsAmt,
	 			eachEstRntAmt:prjQuatPrps.eachEstRntAmt,
	 			lsCalWayCd:prjQuatPrps.lsCalWayCd,
	 			lsCoe:prjQuatPrps.lsCoe,
	 			intRateWayCd:prjQuatPrps.intRateWayCd,
	 			dpstHdlWayCd:prjQuatPrps.dpstHdlWayCd,
	 			expHdlWayCd:prjQuatPrps.expHdlWayCd,
	 			noPayWayCd:prjQuatPrps.noPayWayCd,
	 			quatSplitPct:prjQuatPrps.quatSplitPct,
	 			irrPct:prjQuatPrps.irrPct,
	 			irrPct2:prjQuatPrps.irrPct2,
	 			initLsPc:prjQuatPrps.initLsPc,
	 		 }); 
	 		$("#isAllowChg").val(prjQuatPrps.isAllowChg);
	 		$("#isAllowAdd").val(prjQuatPrps.isAllowAdd);
	 		
	 		$("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
	 		$("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
			$("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
			$("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
			$("#splitPctValue").val(prjQuatPrps.quatSplitPct);//拆分比例
			annIntRatePct = prjQuatPrps.annIntRatePct;
	 		var isAllowAdd = $("#isAllowAdd").val();
	 		if(isAllowAdd&&isAllowAdd==CommonConstant.C_YN_N){
	 			$("#addBtn").hide();
	 			$("#delBtn").hide();
	 		}
	 		//初始化费用明细
	 		  var url = '<%=path%>/project/prjquatprps/getPrjQuatCarDetailByIdForDetailPage.do?id='+prpsId+'&&prjId='+prjId;
	 			prjQuatPrpsfeeGrid(url,editFlag);
	 			//初始化合同费用明细
	 			  var url = '<%=path%>/project/prjquatprps/getPrjQuatContFeeDetailById.do?id='+prpsId+'&&prjId='+prjId;
	 				prjQuatPrpsContFeeGrid(url,editFlag);
	 			//初始化支付表明细
	 				var flag = false;
	 				initCalculatePage(flag);
	 				showInitLsPct();
	}
});
function prjQuatPrpsContFeeGrid(url,editFlag){
	contFeeGrid = $("#ligergrid_cont_fee").ligerGrid({
		url:url,
        method: 'get',
        columns: [
            {display: '费用类型', name: 'feeTypCdNm', minWidth: 80},
            {display: '是否为固定值', name: 'isFixedAmtNm', minWidth: 80},
            {display: '计算基数', name: 'calBaseCdNm', minWidth: 80},
            {display: '比例值（%）', name: 'feePct', minWidth: 80, type: 'numberbox' },
            {display: '金额（元）', name: 'feeAmt', minWidth: 80, render:renderAmt},
            {display: '计入方式', name: 'cntWayCdNm', minWidth: 80 }
        ],
        usePager: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: 300,
        heightDiff: -2,
        enabledEdit: editFlag,
        isScroll: false,
        checkbox: false,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        enabledSort: false
    });
	}

function prjQuatPrpsfeeGrid(url,editFlag){
	feeGrid = $("#ligergrid_fee").ligerGrid({
		url:url,
        method: 'get',
        columns: [
            {display: '费用类型', name: 'feeTypCdNm', minWidth: 80},
            {display: '是否为固定值', name: 'isFixedAmtNm', minWidth: 80},
            {display: '计算基数', name: 'calBaseCdNm', minWidth: 80},
            {display: '比例值（%）', name: 'feePct', minWidth: 80, type: 'numberbox' },
            {display: '金额（元）', name: 'feeAmt', minWidth: 80, render:renderAmt},
            {display: '计入方式', name: 'cntWayCdNm', minWidth: 80 }
        ],
        usePager: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: 300,
        heightDiff: -2,
        enabledEdit: false,
        isScroll: false,
        checkbox: editFlag,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        enabledSort: false
    });
	}
	function initCalculatePage(flag){
			 var prpsId=$("#prpsId").val();
		 calculateGrid = $("#ligergrid_calculate").ligerGrid({
			 url:'<%=path%>/project/prjquatprps/getPrjQuatPayById.do?id='+prpsId+'&&prjId='+prjId,
	        method: 'get',
		     columns: [
		         { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
		         { display: '期次', name: 'payPd',minWidth: 140},
		         { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,editor: {type: 'number',
		        	 precision:2,
	    				toFix:true,	
	    				onToFix:function(){
    					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
    				}	 
		         }, enabledSort:true},
		         { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
		        	 render:renderAmt},
		         { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
		        		 render:renderAmt},
		         { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
		        			 render:renderAmt},
		     ],
		     usePager: false,
		     pageSize:10,
		     root:'rows',
		     record:'total',
		     hideLoadButton : true,
		     width: '100%',
		     height:300,
		     heightDiff:-2,
		     //isScroll: false,
		     checkbox:false,
		     enabledEdit: flag,
		     rownumbers:true
		});
	}
	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
		value = Number(value);
		if(typeof value =='number'){
        var h="￥" + FormatMoney((parseFloat(value)).toFixed(2));
        return h;
		}
    }
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function showInitLsPct(){
		var payWayCd = $("#payWayCd").val();
		if(payWayCd&&payWayCd==ProjectConstant.CODE_MULTI__STEP_INTER_ZC){
			$("#initLsPcDiv").show();
		}else{
			$("#initLsPcDiv").hide();
		}
	}
	
</script>



</body>
</html>
